package com.pointstar.dp.modules.project.service.impl;

import com.pointstar.dp.common.entity.Page;
import com.pointstar.dp.common.entity.Query;
import com.pointstar.dp.common.entity.R;
import com.pointstar.dp.common.utils.CommonUtils;
import com.pointstar.dp.modules.project.dao.ProjectRepairRecordMapper;
import com.pointstar.dp.modules.project.entity.ProjectRepairRecordEntity;
import com.pointstar.dp.modules.project.service.ProjectRepairRecordService;
import com.pointstar.dp.modules.project.util.EntityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 报修记录表
 * @author zhukerui
 */
@Service("projectRepairRecordService")
public class ProjectRepairRecordServiceImpl implements ProjectRepairRecordService {

	private final ProjectRepairRecordMapper projectRepairRecordMapper;

    @Autowired
    public ProjectRepairRecordServiceImpl(ProjectRepairRecordMapper projectRepairRecordMapper) {
        this.projectRepairRecordMapper = projectRepairRecordMapper;
    }

    /**
     * 分页查询
     * @param params
     * @return
     */
	@Override
	public Page<ProjectRepairRecordEntity> listProjectRepairRecord(Map<String, Object> params) {
		Query query = new Query(params);
		Page<ProjectRepairRecordEntity> page = new Page<>(query);
		projectRepairRecordMapper.listForPage(page, query);
		return page;
	}

    /**
     * 新增
     * @param projectRepairRecord
     * @return
     */
	@Override
	public R saveProjectRepairRecord(ProjectRepairRecordEntity projectRepairRecord) {
		int count = projectRepairRecordMapper.save((ProjectRepairRecordEntity) EntityUtil.convertEntity(projectRepairRecord));
		return CommonUtils.msg(count);
	}

    /**
     * 根据id查询
     * @param id
     * @return
     */
	@Override
	public R getProjectRepairRecordById(Long id) {
		ProjectRepairRecordEntity projectRepairRecord = projectRepairRecordMapper.getObjectById(id);
		return CommonUtils.msg(projectRepairRecord);
	}

    /**
     * 修改
     * @param projectRepairRecord
     * @return
     */
	@Override
	public R updateProjectRepairRecord(ProjectRepairRecordEntity projectRepairRecord) {
		int count = projectRepairRecordMapper.update((ProjectRepairRecordEntity) EntityUtil.convertEntity(projectRepairRecord));
		return CommonUtils.msg(count);
	}

    /**
     * 删除
     * @param id
     * @return
     */
	@Override
	public R batchRemove(Long[] id) {
		int count = projectRepairRecordMapper.batchRemove(id);
		return CommonUtils.msg(id, count);
	}
}
